<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>一隅立画</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/css/swiper.min.css">
		<link rel="stylesheet" type="text/css" href="./css/search.css" />
		<link rel="stylesheet" type="text/css" href="./css/headfoot.css" />
		<link rel="stylesheet" type="text/css" href="./css/basestyle.css" />
		<script src="js/base.js"></script>
	</head>
	<body style="background-color: #f2f3f5;">
		<!-- pc头部 -->
			<script src="js/head.js"></script>
			<script src="js/xshead.js"></script>
			<div id="app">
				<div ref='searchnone' style="display: none;">
					<div id="content">
						<div class="container">
							<div class="row">
								<div id="subject" class="col-lg-12">
									<div class="nowracecontent">
										<div v-show="typeid == 1" class="nowracecontentitem col-lg-4 col-md-6 col-xs-6" v-for="(match,index) in matchlist"  @click="opendetail(index,$event)">
											<div class="nowracecontentitemup">
												<div class="nowracecontentitemupimg">
													<img class="nowracecontentworks" :src="match.image">
												</div>
												<div class="shoucang" @click.stop="changcoll(index,match.id,match.collstatus)">
													<img v-show="match.collstatus == 1" src="./images/yishoucang.png" >
													<img v-show="match.collstatus == 0" src="./images/weishoucnag.png" >
												</div>
											</div>
											<div class="nowracecontentitemdown">
												<div class="shejiitemtitle">
													<p>{{match.title}}</p>
												</div>
												<div class="shejiitemstatue">
													<div class="shejiitemstatuele">
														<p v-show="languagestatus == 1">截止时间:</p>
														<p v-show="languagestatus == 2">deadline:</p>
														<p>{{match.endtime}}</p>
													</div>
													<div class="shejiitemstatueri">
														<div class="shejiitemstatueriimg">
															<img v-show="match.keep == 0" src="./images/jingsai_bg.png">
															<img  v-show="match.keep == 1" src="./images/jingsai_bg_end.png" >
															<div class="shejiitemstatueritxt">
																<p v-show="match.keep == 0&&languagestatus == 1">进行中</p>
																<p v-show="match.keep == 1&&languagestatus == 1">已结束</p>
																<p v-show="match.keep == 0&&languagestatus == 2">have in hand</p>
																<p v-show="match.keep == 1&&languagestatus == 2">It's over</p>
															</div>
														</div>
													</div>
												</div>
												<div class="shejiitemworker">
													<div class="shejiitemworkerpeo">
														<div class="shejiitemworkerpeoimg">
															<img :src="match.avatar">
														</div>
														<div class="shejiitemworkerpeoname">
															<p>{{match.nickname}}</p>
														</div>
													</div>
													<div class="shejiitemworkermoney">
														<p>¥</p>
														<p>{{match.money}}</p>
													</div>
												</div>
											</div>
										</div>
										<div v-show="typeid == 2" class="workstrackitem col-lg-4 col-md-6 col-xs-6" v-for="(works, index) in workslist">
											<div class="workstrackitemup">
												<img :src="works.image">
												<div class="workstrackitemupdianzan">
													<div class="workstrackitemupdianzanicon" @click="changstatus(index, works.id, works.likestatus)">
														<img v-show="works.likestatus == 0" src="./images/dainzan_icon.png" >
														<img v-show="works.likestatus == 1" src="./images/dianzan_icon_hover.png" >
													</div>
													<div class="">
														<span>{{works.like}}</span>
													</div>
												</div>
											</div>
											<div class="workstrackitemdown">
												<div class="workstrackitemdowntitle">
													<p @click="openworkdetail(index)">{{works.sheji_competition_title}}</p>
												</div>
												<div class="workstrackitemdownworker">
													<div class="workstrackitemdownworkerone">
														<div class="workstrackitemdownworkeronetxt">
															<p v-show="languagestatus == 1">发布者:</p>
															<p v-show="languagestatus == 2">Publisher:</p>
														</div>
														<div class="workstrackitemdownworkeronetxtinfo">
															<div class="workstrackitemdownworkeronetxtinfoimg">
																<img :src="works.avatar">
															</div>
															<div class="workstrackitemdownworkeronetxtinfoname">
																<p>{{works.nickname}}</p>
															</div>
														</div>
													</div>
													<div class="workstrackitemdownworkerone">
														<div class="workstrackitemdownworkeronetxt">
															<p v-show="languagestatus == 1">设计者:</p>
															<p v-show="languagestatus == 2">designer:</p>
														</div>
														<div class="workstrackitemdownworkeronetxtinfo">
															<div class="workstrackitemdownworkeronetxtinfoimg">
																<img :src="works.designeravatar">
															</div>
															<div class="workstrackitemdownworkeronetxtinfoname">
																<p>{{works.designer}}</p>
															</div>
														</div>
													</div>
												</div>
											</div>
										</div>
										<div class="empty" v-show="typeid == 1&&!matchlist">
											<div class="emptywarp">
												<div class="emptywarpimg">
													<img src="images/empty.png" >
												</div>
												<p>暂无数据</p>
											</div>
										</div>
										<div class="empty" v-show="typeid == 2&&!workslist">
											<div class="emptywarp">
												<div class="emptywarpimg">
													<img src="images/empty.png" >
												</div>
												<p>暂无数据</p>
											</div>
										</div>
										<div class="clear"></div>
									</div>
									<!-- 分页 -->
									<div class="fenye" v-show="itemlist>1">
										<ul>
											<li class="fenyeitem" @click="getprve(nowpage-1)"><img src="./images/prve_icon.png" ></li>
											<li v-for="item in itemlist" @click="getcur(item)" :class="{showeffect :item ==nowpage?true:false}">{{item}}</li>
											<li @click="getnext(nowpage+1)"><img src="./images/next_icon.png" ></li>
											<div class="clear"></div>
										</ul>
									</div>
									<!-- 提示 -->
									<div>
										<div class="judgepopup" v-show="tippopup == 1">
											<div class="judgepopupnav">
												<div class="judgepopupwarp">
													<div class="judgepopupwarpup">
														<img src="./images/revoke_logo.png">
													</div>
													<div class="judgepopupwarpdown">
														<div class="judgepopupwarptxt">
															<p v-show="languagestatus == 1 && done == 1">您还未登录，请先登录在进行收藏吧!</p>
															<p v-show="languagestatus == 2 && done == 1">You haven't logged in yet, please log in to collect first!</p>
															<p v-show="languagestatus == 1 && done == 2">您还未登录，请先登录在进行点赞吧!</p>
															<p v-show="languagestatus == 2 && done == 2">You haven't logged in yet, please log in to like it first!</p>
														</div>
														<!-- <div class="judgepopupwarpbtn">
															<div class="judgepopupwarpbtnitem judgepopupwarpbtnactive" @click="closetipopup">
																<p v-show="languagestatus == 1">好的</p>
																<p v-show="languagestatus == 2">OK</p>
															</div>
														</div> -->
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>


			<script src="js/pcFooter.js" type="text/javascript"></script>
		<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/js/swiper.min.js"></script>
		<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
		<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.min.js"></script>
		<script type="text/javascript">
			// pc头部
			let app = new Vue({
				el: '#app',
				data: {
					searchpage:1,
					tipcontent:0,
					typePage:0,
					username: '',
					icon: '',
					headPortrait: './images/touxiang.png',
					getCode: true,
					logingetCode: true,
					navBarFixed:false,
					count: '',
					logincount: '',
					num: 0,
					nav: 2,
					type: 1,
					page: 1,
					seachopen: false,
					password: 0,
					phonecode: 0,
					phonecodelogin: 0,
					logintype: 0,
					loginstatuscode: 0,
					loginstatus: 0,
					searrchlist: [],
					loginphone: '',
					loginpassword: '',
					loginphonecode: '',
					logincode: '',
					zucephone: '',
					zhucecode: '',
					zhucepassword: '',
					zhucemakesurepassword: '',
					searchcontent:'',
					userid:'',
					token:'',
					usersearch:[],
					recordcontent:'',
					typeid:1,
					tanchuang1:0,
					paixu: 1,
					showicon:false,
					matchlist: [],
					ids:[],
					itemlist:'',
					nowpage:1,
					current:0,
					fenyepage:0,
					status:0,
					statusjudge:false,
					workslist:[],
					idsLike:'',
					languagestatus: '',
					done:0,
					tippopup:0,
				},
				created:function() {
					if (sessionStorage.getItem('languagestatus')) {
						let languagestatus = sessionStorage.getItem('languagestatus')
						this.languagestatus = languagestatus
					}
					if(sessionStorage.getItem('typeid')){
						this.typeid = sessionStorage.getItem('typeid')
					}
					if(sessionStorage.getItem('content')){
						this.searchcontent = sessionStorage.getItem('content')
					}
				},
				mounted:function() {
					let that = this
					// var url = location.search
					// var theRequest = new Object()
					// if (url.indexOf("?") != -1) {
					// var str = url.substr(1); //substr()方法返回从参数值开始到结束的字符串；
					// var strs = str.split("&");
					// 	for (var i = 0; i < strs.length; i++) {
					// 		theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
					// 	}
					// 	// console.log( theRequest ); //此时的theRequest就是我们需要的参数；
					// 	let redirect_ur = decodeURI(theRequest.content) //url解码
					// 	// let redirect_ur = encodeURI(theRequest.content) //url编码
					// 	that.typeid = theRequest.id
					// 	that.searchcontent = redirect_ur
					// 	if(that.typeid == 1){
					// 		that.typesearch0 = '竞赛'
					// 	}else{
					// 		that.typesearch0 = '追踪'
					// 	}
					// 	console.log(theRequest)
					// }
					if (localStorage.getItem('logininfo')) {
						console.log('isdfksjdf sd')
						let obj = JSON.parse(localStorage.getItem('logininfo'));
						console.log(obj)
						that.loginstatus = 1
						that.userid = obj.userid
						that.token = obj.token
					}
					if (localStorage.getItem('userinfo')) {
						let obj = JSON.parse(localStorage.getItem('userinfo'));
						console.log(obj)
						that.loginstatus = 1
						that.username = obj.nickname
						that.icon = obj.avatar
					}
					that.getmatchlist()
					this.$refs.searchnone.style.display = 'block'
					
				},
				destroyed() {
					
				},
				methods: {
					
					// 时间转换
					add0(m){return m<10?'0'+m:m },
					getLocalTime(nS) {
					   let time = new Date(parseInt(nS)*1000);
					   var y = time.getFullYear();
					   var m = time.getMonth()+1;
					   var d = time.getDate();
					   var h = time.getHours();
					   var mm = time.getMinutes();
					   var s = time.getSeconds();
					   return y+'/'+this.add0(m)+'/'+this.add0(d)+' '+this.add0(h)+':'+this.add0(mm);
					},
					// 搜索历史
					getsearrchlist: function() {
						let that = this
						axios.get('http://admin.yiyulihua.com/api/sheji.index/searchList', {
								params:{
									userid: that.userid,
									token: that.token
								}
							})
							.then((res) => {
								if(res.data.code == 1){
									that.usersearch = res.data.data.usersearch
								}
								console.log(res)
							})
					},

					// 收藏
					changcoll:function(i,id,type){
						let that = this
						if(type == 0){
							type = 1
						}else if(type == 1){
							type = 0
						}
						axios.get('http://admin.yiyulihua.com/api/sheji.competition/collection',{
							params:{
								userid:that.userid,
								token:that.token,
								id:id,
								type:type
							}
						})
						.then((res) =>{
							console.log(res)
							if(res.data.code == 1){
								let list = that.matchlist
								list.forEach((item ,index) =>{
									if(index == i && item.collstatus == 1){
										item.collstatus = 0
									}else if(index == i && item.collstatus == 0){
										item.collstatus = 1
									}
								})
								that.matchlist = list
							}else if(res.data.code == 2){
								that.done = 1
								that.tippopup = 1
								setTimeout(function(){
									that.tippopup = 0
								},1300)
							}
						})
					},
					
					// 竞赛中心列表
					getmatchlist:function(){
						let that = this
						if(that.typeid == 1){
							axios.get('http://admin.yiyulihua.com/api/sheji.index/competitionSearch',{
								params:{
									userid:that.userid,
									token:that.token,
									text:that.searchcontent,
									page:that.nowpage,
								},
							})
							.then((res) =>{
								if(res.data.code == 1){
									that.matchlist = res.data.data.searchlist
									that.itemlist = res.data.data.pagenum
									that.nowpage = res.data.data.page
									let list = res.data.data.searchlist
									list.forEach((item,index) =>{
										item.endtime = that.getLocalTime(item.endtime)
									})
									if(res.data.data.searchlist.length > 0){
										that.fenyepage = 1
									}
								}
							})
						}else if(that.typeid == 2){
							axios.get('http://admin.yiyulihua.com/api/sheji.index/trackSearch',{
								params:{
									userid:that.userid,
									token:that.token,
									text:that.searchcontent,
									page:that.nowpage
								}
							})
							.then((res) =>{
								console.log(res)
								if(res.data.code == 1){
									that.workslist = res.data.data.searchlist
									that.itemlist = res.data.data.pagenum
								}
								console.log(that.typeid)
							})
						}
					},
					// 点赞/取消点赞
					changstatus:function(i, id, type){
						let that = this
						let list = that.workslist;
						if(type == 1) {
							type = 0
						}else if(type == 0) {
							type = 1
						}
						console.log(type)
						axios.get('http://admin.yiyulihua.com/api/sheji.track/like',{
							params:{
								userid:that.userid,
								token:that.token,
								id: id,
								type:type
							}
						})
						.then((res) =>{
							console.log(res);
							if(res.data.code == 1){
								list.forEach((item, index) => {
									if(index == i && item.likestatus == 1) {
										item.likestatus = 0;
										item.like--;
									}else if(index == i && item.likestatus == 0) {
										item.likestatus = 1;
										item.like++
									}
								})
								that.workslist = list
							}else if(res.data.code == 2){
								that.done = 2
								that.tippopup = 1
								setTimeout(function(){
									that.tippopup = 0
								},1300)
							}
									
						})
						
						
					},
					// 跳转页面
					opendetail:function(index){
						let that = this
						axios.get('http://admin.yiyulihua.com/api/sheji.competition/views',{
							params:{
								userid:that.userid,
								token:that.token,
								id:that.matchlist[index].id
							}
						})
						.then((res) =>{
							console.log(res)
							window.location.href = 'jingsaidetail.html?id='+that.matchlist[index].id
						})
					}
				}
			})
			
		
		</script>
	</body>
</html>
